import request from '@/utils/request';

/**
 * 获取权限tree
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const getPermissionTree = () => {
  return request<API.permission.TreeSchema[]>({
    url: '/admin/permission/tree',
    method: 'get'
  });
};

/**
 * 添加权限
 *
 * @param data: Permission
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const addPermission = (data: any) => {
  return request({
    url: '/admin/permission',
    method: 'post',
    data
  });
};

/**
 * 编辑权限
 *
 * @param id
 * @param data: Permission
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const updatePermission = (id: number, data: any) => {
  return request({
    url: '/admin/permission/' + id,
    method: 'put',
    data
  });
};

/**
 * 更新switch状态
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const updateSwitch = (id: number, data: any) => {
  return request({
    url: `/admin/permission/switch/${id}`,
    method: 'put',
    data
  });
};

/**
 * 删除权限
 *
 * @param id
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const deletePermission = (id: number) => {
  return request({
    url: '/admin/permission/' + id,
    method: 'delete'
  });
};
